<?php
	if($user != null && $user['rank'] > 0)
	{
		$data = array(
	    "id" => "newBlogPostButton",
	    "name" => "newBlogPostButton",
	    "type" => "submit",
	    "value" => "Blogga");
		
		$attributes = array(
	    "name" => "newBlogPostForm",
	    "id" => "newBlogPostForm"
	    );
	    
		echo "<a href='javascript:void(0)' class='openNewBlogPost'>Nytt inlägg</a>" .
		"<div id='newBlogPost'>".
			form_open(current_url(), $attributes) .
			"<p>" . form_input("headline") . "</p>"
			."<p>". form_textarea("message") . "</p>"
			."<p>". form_submit($data) . "</p>" .
			form_close() . "
		</div>";	
	
		echo 
		"<div class='validation'>"
			. validation_errors() .
		"</div>";
	}

	
	foreach($blogposts as $post)
	{
		echo 
		"<div class='blogPost'>
			<p>" 
				. substr($post['posted'],0,10) . " - <span class='blogHeadline'>" . $post['headline'] . "</span>
			</p>
			<p>"  
				. nl2br($post['message']) . 
		   "</p>
		   <p class='blogCommentLinkWrapper'>
				<a href='".site_url()."/home/comments/".$post['id']."'>Comments(".$post['comments'].")</a>
		   </p>
		</div>";
	}
	
	echo $paging;